fd92d8
@@ -177,6 +177,20 @@
protected abstract Object process(ReduceSinkOperator cRS, GroupByOperator cGBY,
 
   static class GroupbyReducerProc extends AbsctractReducerReducerProc {
 
+    // given a group by operator this determines if that group by belongs to semi-join branch
+    // note that this works only for second last group by in semi-join branch (X-GB-RS-GB-RS)
+    private boolean isSemiJoinBranch(final GroupByOperator gOp, ReduceSinkDeduplicateProcCtx dedupCtx) {
+      for(int i=0; i<gOp.getChildren().size(); i++) {
+        if(gOp.getChildren().get(i) instanceof  ReduceSinkOperator) {
+          ReduceSinkOperator rsOp = (ReduceSinkOperator)gOp.getChildren().get(i);
+          if(dedupCtx.getPctx().getRsToSemiJoinBranchInfo().containsKey(rsOp)) {
+            return true;
+          }
+        }
+      }
+      return false;
+    }
+
     // pRS-pGBY-cRS
     @Override
     public Object process(ReduceSinkOperator cRS, ReduceSinkDeduplicateProcCtx dedupCtx)
@@ -187,6 +201,9 @@
public Object process(ReduceSinkOperator cRS, ReduceSinkDeduplicateProcCtx dedup
       if (pGBY == null) {
         return false;
       }
+      if(isSemiJoinBranch(pGBY, dedupCtx)) {
+        return false;
+      }
       ReduceSinkOperator pRS =
           CorrelationUtilities.findPossibleParent(
               pGBY, ReduceSinkOperator.class, dedupCtx.trustScript());
@@ -211,6 +228,9 @@
public Object process(ReduceSinkOperator cRS, GroupByOperator cGBY,
       if (pGBY == null) {
         return false;
       }
+      if(isSemiJoinBranch(cGBY, dedupCtx)) {
+        return false;
+      }
       ReduceSinkOperator pRS =
           CorrelationUtilities.getSingleParent(pGBY, ReduceSinkOperator.class);
       if (pRS != null && ReduceSinkDeDuplicationUtils.merge(cRS, pRS, dedupCtx.minReducer())) {
